<?php
    header("Content-type:text/html;charset=utf-8");
    //创建链接
    $link = mysqli_connect("localhost","root","","my_database");
    //数据库链接错误
    if (!$link) {
        exit("数据库链接错误".mysqli_connect_error());
    } 
    //数据库字符集出错
    if (!mysqli_set_charset($link,"utf8")) {
        exit("字符集设置错误:".mysqli_error($link));
    }

    //测试成功
    // echo "链接数据库成功！";